<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">


            <ui:define name="content">
                <h:form id="form">
                        <p:panel header="Purchase Order: Choose a Sales Quotation" style="height:495px;">
                            <p:growl id="statusMessage" showDetail="true" />
                            <div style="margin-top:20px;margin-left:50px;margin-right:50px;">
                                <p:dataTable id="inquiry" value="#{convertSalesQuotationManagedbean.getSalesQuotations()}" var="inList" paginator="true" rows="6">

                                    <p:column filterBy="#{inList.id}" filterMatchMode="contains"
                                              headerText="Quotation ID">
                                        <h:outputText value="#{inList.id}"/>
                                    </p:column>
                                    <p:column filterBy="#{inList.company.name}" filterMatchMode="contains"
                                              headerText="Client">
                                        <h:outputText value="#{inList.company.name}"/>
                                    </p:column>

                                    <p:column filterBy="#{inList.company.salesman.name}" filterMatchMode="contains"
                                              headerText="Processed By">
                                        <h:outputText value="#{inList.company.salesman.name}"/>
                                    </p:column>

                                    <p:column headerText="Action" style="text-align: center;width:90px;">
                                        <p:commandButton update="form:display" oncomplete="viewDetailsDialog.show()" image="ui-icon ui-icon-search" title="View" actionListener="#{convertSalesQuotationManagedbean.viewProcessing}" style="margin-right:10px;">
                                            <f:attribute name="ViewQuotation" value="#{inList}"/>
                                        </p:commandButton>
                                        <p:commandButton action ="#{convertSalesQuotationManagedbean.redirect(inList)}" image="ui-icon ui-icon-check" title="Select" update="statusMessage" />        
                                    </p:column>  

                                </p:dataTable>  
                            </div> 

                            <p:dialog header="Quotation Detail" widgetVar="viewDetailsDialog" resizable="false" id="viewDetails" showEffect="fade" hideEffect="explode" modal="true" width="1000">  

                                <p:outputPanel id="display">
                                    <h:panelGrid id="dis" columns="2" cellpadding="0">  
                                        <h:outputText value="Quotation ID" />  
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.id}" style="font-weight:bold"/>  
                                        </h:panelGroup>  

                                        <h:outputText value="Company" />  
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.company.name}" style="font-weight:bold"/>  
                                        </h:panelGroup> 

                                        <h:outputText value="Raise Date" /> 
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.raiseDate}" style="font-weight:bold">  
                                                <f:convertDateTime pattern="dd-MM-yyyy" />
                                            </h:outputText>
                                        </h:panelGroup>

                                        <h:outputText value="Valid Until" /> 
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.validUntil}" style="font-weight:bold">  
                                                <f:convertDateTime pattern="dd-MM-yyyy" />
                                            </h:outputText>
                                        </h:panelGroup>  

                                        <h:outputText value="User Discount" />  
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.userDiscount}" style="font-weight:bold"/>  
                                        </h:panelGroup> 

                                        <h:outputText value="Total Price" />  
                                        <h:panelGroup>  
                                            <h:outputText value="#{convertSalesQuotationManagedbean.temp.totalPrice}" style="font-weight:bold"/>  
                                        </h:panelGroup>

                                    </h:panelGrid>

                                    <p:dataTable id="lineItemDetail" dynamic="true" emptyMessage="No Line Items are founded" value="#{convertSalesQuotationManagedbean.temp.quotationLineItems}" var ="l" >

                                        <p:column  >
                                            <f:facet name="header">Product Name</f:facet>
                                            #{l.product.productName}
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Quantity</f:facet>
                                            #{l.quantity}
                                        </p:column> 

                                        <p:column>
                                            <f:facet name="header">Lead Time</f:facet>
                                            #{l.leadTime}
                                        </p:column> 

                                        <p:column>
                                            <f:facet name="header">Original Unit Price</f:facet>
                                            <h:outputText value="#{l.product.basePrice}" />
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Promotional Price</f:facet>
                                            <h:outputText value="#{l.product.promotionPrice}" />
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Discount</f:facet>
                                            <h:outputText value="#{l.discount}" />
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Unit Price</f:facet>
                                            #{l.price}
                                        </p:column> 

                                        <p:column>
                                            <f:facet name="header">Subtotal</f:facet>
                                            <h:outputText value="#{l.cumAmount}" />
                                        </p:column>
                                    </p:dataTable>


                                </p:outputPanel>
                            </p:dialog>

                        </p:panel>
                </h:form>   
            </ui:define>

        </ui:composition>

    </body>
</html>
